/*
 * 作者：贺智远
 * 功能：实现姚俊的从Excel信息导入到数据库当中的接口
 * 日期：2015-06-26
 */
package tools;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import teacher.bean.Award;
import teacher.bean.Paper;
import teacher.bean.Patent;
import teacher.bean.Project;
import teacher.bean.Teacher;
import teacher.bean.Treatise;
import teacher.service.award;
import teacher.service.paper;
import teacher.service.patent;
import teacher.service.project;
import teacher.service.teacher;
import teacher.service.treatise;
import admin.databaseToExcel.GetInfoByExcel;

public class FruitsToDbService implements FruitsToDbInterface{

	public void PaperToDb(String File) {
		// TODO Auto-generated method stub
		
		List<Map<Integer,String>> maps=new ArrayList<Map<Integer,String>>();
		
		List<Teacher> teachers=new teacher().SelectAllTeacher();
		
		maps=GetInfoByExcel.getAllByExcel(File);				
		for(int i=0;i<maps.size();i++)
		{
			Paper paper=new Paper();
			paper.setName(maps.get(i).get(1));
			paper.setFauthor(maps.get(i).get(2));
			paper.setPbulication(maps.get(i).get(3));
			paper.setPubNumber(maps.get(i).get(4));
			paper.setInclude(Integer.parseInt(maps.get(i).get(5)));
			paper.setQuoteNum(Integer.parseInt(maps.get(i).get(6)));
			paper.setPapId(0);
			paper.setState(RandomCreateNum.createNum(4,5));
			paper.setUpload("paper.rar");
			paper.setPubPage("0");
			paper.setDate(StringDate.StringToDate("2013-02-21"));
			paper.setTopStu(RandomCreateNum.createNum(0, 3));
			paper.setTauthor("张贵军 ，徐建明");
			paper.setOauthor("徐建明"); 
			paper.setVolume("0"); 
			for(int j=0;j<teachers.size();j++)
			{
				if(teachers.get(j).getName().contains(paper.getFauthor()))
				{
					paper.setTeaId(teachers.get(j).getTeaId()); 
					break;
				}
				
			}
			if(paper.getTeaId()==null)
			paper.setTeaId(RandomCreateNum.createNum(373, 423)); 	
			paper.setType(0); 
			paper.setEsi(0); 
			paper.setJclass(0); 
			paper.setIncludNum("0"); 
			paper.setMeetClass(0); 
			paper.setMeetName("0"); 
			paper.setMeetPlace("0"); 	
			paper pp=new paper();
			pp.insertPaper(paper);
		}
		
	}

	public void TreatiseToDb(String File) {
		// TODO Auto-generated method stub
		List<Map<Integer,String>> maps=new ArrayList<Map<Integer,String>>();	
		List<Teacher> teachers=new teacher().SelectAllTeacher();
		maps=GetInfoByExcel.getAllByExcel(File);			
		for(int i=0;i<maps.size();i++)
		{
			Treatise treatise=new Treatise();
			treatise.setName(maps.get(i).get(1));
			treatise.setAuthor(maps.get(i).get(2));
			treatise.setDate(StringDate.StringToDate("2003-09-03"));
			treatise.setState(RandomCreateNum.createNum(4,5));
			treatise.setClass_(0);
			treatise.setPress("清华大学出版社");
			treatise.setAbstract_("本书适合高等院校本科生及以上学历使用");
			treatise.setUpload("treatise.rar");
			treatise.setBookNum(String.valueOf(RandomCreateNum.createNum(10000,99999)));
			for(Teacher t:teachers)
			{
				if(treatise.getAuthor().contains(t.getName()))
				{
					treatise.setTeaId(t.getTeaId()); 
					break;
				}
				
			}
			if(treatise.getTeaId()==null)
			treatise.setTeaId(RandomCreateNum.createNum(373, 423));
			treatise treatise0=new treatise();
			treatise0.insertTreatise(treatise);
		}
		
	}

	public void PatentToDb(String File) {
		// TODO Auto-generated method stub
		List<Map<Integer,String>> maps=new ArrayList<Map<Integer,String>>();	
		List<Teacher> teachers=new teacher().SelectAllTeacher();
		maps=GetInfoByExcel.getAllByExcel(File);			
		for(int i=0;i<maps.size();i++)
		{
			Patent p=new Patent();
		
			p.setName(maps.get(i).get(1));
			p.setFiestInventor(maps.get(i).get(4));
			p.setEmpowerDate(StringDate.StringToDate("2003-09-03"));
			p.setEmpowerUnit(maps.get(i).get(6));
			p.setTransferFunds(RandomCreateNum.createNum(5,20));
			p.setExamine(RandomCreateNum.createNum(4,5));
			p.setApplyNumber(maps.get(i).get(2));
			p.setNumber(maps.get(i).get(3));
			p.setUpload("patent.rar");
			for(Teacher t:teachers)
			{
				if(p.getFiestInventor().equals(t.getName()))
				{
					p.setTeaId(t.getTeaId()); 
					break;
				}
				
			}
			if(p.getTeaId()==null)
			p.setTeaId(RandomCreateNum.createNum(373, 423)); 	
			p.setExpClass(RandomCreateNum.createNum(0,2));
			p.setEmpowerNum(String.valueOf(RandomCreateNum.createNum(10000,99999)));
			p.setApplyDate(StringDate.StringToDate("2003-09-03"));
			patent patent1=new patent();
			patent1.insertPatent(p);
		}
		
		
		
	}

	public void ProjectToDb(String File) {
		// TODO Auto-generated method stub
		List<Map<Integer,String>> maps=new ArrayList<Map<Integer,String>>();
		
		List<Teacher> teachers=new teacher().SelectAllTeacher();
		
		maps=GetInfoByExcel.getAllByExcel(File);		
		System.out.println(maps.size());
		System.out.println(maps.get(0).get(5));
		
		for(int i=0;i<maps.size();i++)
		{
			Project p=new  Project();
			p.setName(maps.get(i).get(2));
			p.setLevel(RandomCreateNum.createNum(0,3));
			p.setSource(maps.get(i).get(3));
			if(maps.get(i).get(4)!=null)
			{
				p.setFunds(Double.valueOf(maps.get(i).get(4)).intValue());
			}
			else
				p.setFunds(0);
			p.setArriveFunds(Double.valueOf(maps.get(i).get(5)).intValue());
			p.setLeader(maps.get(i).get(6));
			p.setOthers("张贵军");
			p.setBeginDate(StringDate.StringToDate("2003-09-03"));
			p.setState(RandomCreateNum.createNum(4,5));
			p.setLowDepartment("省厅");
			p.setClass_(RandomCreateNum.createNum(0,6));
			p.setNumber(String.valueOf(RandomCreateNum.createNum(10000,99999)));
			p.setFinishDate(StringDate.StringToDate("2013-09-03"));
			p.setUpload("project.rar");
			for(Teacher t:teachers)
			{
				if(p.getLeader().equals(t.getName()))
				{
					p.setTeaId(t.getTeaId()); 
					break;
				}
				
			}
			if(p.getTeaId()==null)
			p.setTeaId(RandomCreateNum.createNum(373, 423));	
			p.setKind(RandomCreateNum.createNum(0,1));
			p.setProgress(RandomCreateNum.createNum(0,3));
			project project=new project();
			project.insertProject(p);
		}
		
		
	}

	public void AwardToDb(String File) {
		// TODO Auto-generated method stub
		List<Map<Integer,String>> maps=new ArrayList<Map<Integer,String>>();
		List<Teacher> teachers=new teacher().SelectAllTeacher();
		maps=GetInfoByExcel.getAllByExcel(File);			
		for(int i=0;i<maps.size();i++)
		{
			Award a=new Award();			
			a.setName(maps.get(i).get(1));
			a.setProjectName(maps.get(i).get(2));
			a.setLevel(Integer.parseInt(maps.get(i).get(4)));			
			a.setPeople(maps.get(i).get(5));
			a.setDate(StringDate.StringToDate("2010-05-23"));
			a.setNumber(maps.get(i).get(3));
			a.setUpload("award.rar");
			for(Teacher t:teachers)
			{
				if(a.getPeople().contains(t.getName()))
				{
					a.setTeaId(t.getTeaId()); 
					break;
				}
				
			}
			if(a.getTeaId()==null)
			a.setTeaId(RandomCreateNum.createNum(373, 423)); 	
			a.setState(RandomCreateNum.createNum(4,5));
			a.setKind(RandomCreateNum.createNum(0,3));
			a.setUnitNum(RandomCreateNum.createNum(0,2));
			a.setEmpowerUnit("省科技厅");
			award award=new award();
			award.insertAward(a);
		}
	}

}
